package de.homelabs.bookmarkmanager.desktop.qt.handler;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import spiffy.log4j.LoggerHelper;

import com.trolltech.qt.gui.QApplication;

import de.homelabs.bookmarkmanager.desktop.qt.help.AboutDialog;
import de.homelabs.bookmarkmanager.desktop.qt.menu.HAction;
import de.homelabs.bookmarkmanager.desktop.qt.stereotype.Signal;
import de.homelabs.bookmarkmanager.desktop.qt.view.BookmarkManagerMainView;

/**
 * handles action fpr BookmarkManagerMainView<br>
 * <br>
 * @author d.mueller
 *
 */
@Service
public class MainViewActionHandler {
	
	//logger
	public static final Logger logger = LoggerHelper.getLogger();

	@Autowired
	public AboutDialog aboutDialog;
	
	@Autowired
	public BookmarkManagerMainView bmw;
	
	/**
	 * constructor
	 */
	public MainViewActionHandler(){
	}
	
	@Signal(clazz="menuManager", signal="menuActionSignal")
	public void handleAction(HAction action){
		//here we can decide which action to handle
		System.out.println("[mainViewActionHandler] name:"+action.text()+", key:"+action.getActionKey());
		if (action.getActionKey().equalsIgnoreCase("append")){
			//key for ending application
			QApplication.quit();
		}
		if (action.getActionKey().equalsIgnoreCase("aboutinfobox")){
			aboutDialog.move(bmw.pos().x(),bmw.pos().y());
			aboutDialog.show();
		}
	}
}
